package com.yanqu.road.server.cmd.chefduel.process2.cross;

import com.yanqu.road.entity.activity.ActivityInfo;
import com.yanqu.road.entity.activity.chefduel.ChefDuelData;
import com.yanqu.road.entity.enums.eActivityType;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.pb.chefduel.ChefDuelProto;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.command.Command;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.chefduel.ChefDuelModule;
import com.yanqu.road.server.manger.activity.chefduel.ChefDuelActivityMgr;
import com.yanqu.road.server.manger.player.GamePlayerMgr;
import com.yanqu.road.server.protocol.Protocol;
import io.netty.channel.ChannelHandlerContext;

import java.util.List;

@Cmd(code = Protocol.S_CHEF_DUEL2_SETTING_SPOON_CHANGE_FROM_CROSS, desc = "自动回访设置变更同步")
public class ChefDuel2SettingSpoonChangeNotifyCmd implements Command {

    @Override
    public void execute(ChannelHandlerContext ctx, YanQuMessage yanQuMessage) throws Exception {

        ChefDuelProto.ChefDuel2SettingSpoonChangeNotifyMsg notifyMsg = ChefDuelProto.ChefDuel2SettingSpoonChangeNotifyMsg.parseFrom(yanQuMessage.getBytes());

        List<ActivityInfo> openActivityInfoList = ChefDuelActivityMgr.getOpenActivityInfoList(eActivityType.ChefDuel.getValue(), 2);
        if(openActivityInfoList.isEmpty()){
            return;
        }
        ActivityInfo activityInfo = openActivityInfoList.get(0);
        List<GamePlayer> copyPlayerList = GamePlayerMgr.getCopyPlayerList();
        for (GamePlayer player : copyPlayerList) {
            ChefDuelData chefDuelData = player.getModule(ChefDuelModule.class).getChefDuelDataMap().get(activityInfo.getActivityId());
            if(chefDuelData != null && chefDuelData.isAble()){
                player.sendPacket(Protocol.U_CHEF_DUEL2_SETTING_SPOON_CHANGE, notifyMsg.toBuilder());
            }
        }
    }
}
